$(document).ready(function () {
	if (update) {
		$("#update").click(
			function() {
				var width = $(document).width();
				var height = $(document).height();
				$('#opacity').css('width', width + 'px');
				$('#opacity').css('height', height + 'px');
				$('#opacity').css('display', 'block');
				$('#opacity').css('opacity', '0.5');
				$('#image_loadder').css('display', 'block');
				$('#image_loadder').css("left",
						($(window).width() - 100) / 2 + "px");
				$('#image_loadder').css("top",
						($(window).height() - 100) / 2 + "px");
				/*setTimeout(function() {
					window.location = location.href
				}, 60000);*/
				$.get(url_update, function(data) {
						
						$('#opacity').css('display', 'none');
						$('#image_loadder').css('display', 'none');
						window.location = location.href
				});
		});
	}
	
	$(".site-info .country-visitor tr:gt(9)").addClass("hidden");
	if ($(".site-info .country-visitor tr").size() < 10) {
		$(".site-info .view-all").addClass("hidden");
	}
	$(".site-info .view-all").click(function () {
		$(".site-info .country-visitor tr").removeClass("hidden");
		$(this).addClass("hidden");
	});
	
});

var API_KEY = "AIzaSyB-aMH9_2JJCYCSRL578Vnqiio6faclchE", URL_TO_GET_RESULTS_FOR = "http://"
	+ domain, API_URL = "https://www.googleapis.com/pagespeedonline/v1/runPagespeed?", CHART_API_URL = "http://chart.apis.google.com/chart?", callbacks = {};
function runPagespeed() {
	var a = document.createElement("script");
	a.type = "text/javascript";
	a.async = true;
	var b = [ "url=" + URL_TO_GET_RESULTS_FOR,
			"callback=runPagespeedCallbacks", "key=" + API_KEY ].join("&");
	a.src = API_URL + b;
	document.getElementsByTagName("head")[0].insertBefore(a, null);
	document.getElementById("page_speed").children[0].innerHTML = "Loading ...";
}
function runPagespeedCallbacks(c) {
	if (c.error) {
		for ( var b = c.error.errors, a = 0, e = b.length; a < e; ++a)
			if (b[a].reason == "badRequest"
					&& API_KEY == "AIzaSyB-aMH9_2JJCYCSRL578Vnqiio6faclchE")
				alert("Please specify your Google API key in the API_KEY variable.");
			else
				alert(b[a].message);
		return
	}
	for ( var d in callbacks) {
		var f = callbacks[d];
		typeof f == "function" && callbacks[d](c)
	}
}
callbacks.displayPageSpeedScore = function(c) {
	var a = c.score, d = [ "chtt=Page+Speed+score:+" + a, "chs=180x100",
			"cht=gom", "chd=t:" + a, "chxt=x,y", "chxl=0:|" + a ].join("&"), b = document
			.createElement("img");
	b.src = CHART_API_URL + d;
	document.getElementById("page_speed").insertBefore(b, null)
};
var RESOURCE_TYPE_INFO = [ {
	label : "JavaScript",
	field : "javascriptResponseBytes",
	color : "e2192c"
}, {
	label : "Images",
	field : "imageResponseBytes",
	color : "f3ed4a"
}, {
	label : "CSS",
	field : "cssResponseBytes",
	color : "ff7008"
}, {
	label : "HTML",
	field : "htmlResponseBytes",
	color : "43c121"
}, {
	label : "Flash",
	field : "flashResponseBytes",
	color : "f8ce44"
}, {
	label : "Text",
	field : "textResponseBytes",
	color : "ad6bc5"
}, {
	label : "Other",
	field : "otherResponseBytes",
	color : "1051e8"
} ];
callbacks.displayResourceSizeBreakdown = function(k) {
	var d = "page_speed";
	for ( var h = k.pageStats, f = [], i = [], e = [], j = 0, c = 0, a = 0, o = RESOURCE_TYPE_INFO.length; a < o; ++a) {
		var m = RESOURCE_TYPE_INFO[a].label, g = RESOURCE_TYPE_INFO[a].field, l = RESOURCE_TYPE_INFO[a].color;
		if (g in h) {
			var b = Number(h[g]);
			j += b;
			if (b > c)
				c = b;
			f.push(m);
			i.push(b);
			e.push(l)
		}
	}
	var n = [ "chs=300x140", "cht=p3", "chts=" + [ "000000", 16 ].join(","),
			"chco=" + e.join("|"), "chd=t:" + i.join(","),
			"chdl=" + f.join("|"), "chdls=000000,14", "chp=1.6", "chds=0," + c ]
			.join("&"), a = document.createElement("img");
	a.src = "http://chart.apis.google.com/chart?" + n;
	document.getElementById(d).insertBefore(a, null);
	document.getElementById(d).children[0].style.display = "none"
};